package com.example.views;

import com.example.R;
import com.example.interfaces.IAdminUserActivity;
import com.example.presenters.AdminUserPresenter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * This is the class that will allow us to promote a user to an admin, delete
 * users, unlock users, etc.
 * 
 * @author 3Factorial
 */
public class AdminUserActivity extends Activity implements IAdminUserActivity {

	private AdminUserPresenter presenter;
	private TextView userTypeText;
	private TextView isLockedText;
	private Button userTypeButton;
	private Button isLockedButton;
	private String adminName;

	/**
	 * Sets up the activity for the administrators.
	 */
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_admin_user);

		Intent intent = getIntent();
		String username = intent.getStringExtra("USERNAME_TO_ADMIN");//changed from USERNAME_TO_ADMIN - Zach
		adminName = intent.getStringExtra(MainActivity.USERNAME);//I changed from MainActivity.USERNAME to just USERNAME for testing - Zach
		presenter = new AdminUserPresenter(this,
				com.example.model.UserList.getInstance(), username);

		TextView userNameView = (TextView) findViewById(R.id.text_name);
		userTypeText = (TextView) findViewById(R.id.text_usertype);
		userTypeButton = (Button) findViewById(R.id.button_admin);
		isLockedText = (TextView) findViewById(R.id.text_accountstatus);
		isLockedButton = (Button) findViewById(R.id.button_lock);

		userNameView.setText(username);
		presenter.setUserType(userTypeText, userTypeButton);
		presenter.setIsLocked(isLockedText, isLockedButton);
	}

	/**
	 * Changes the user type.
	 * 
	 * @param view
	 */
	public void changeUserType(View view) {
		presenter.changeUserType(userTypeText, userTypeButton);
	}

	/**
	 * Changes whether a user is locked or unlocked to the corersponding other.
	 * 
	 * @param view
	 */
	public void changeIsLocked(View view) {
		presenter.changeIsLocked(isLockedText, isLockedButton);
	}

	/**
	 * Deletes the chosen user from the application.
	 * 
	 * @param view
	 */
	public void deleteUser(View view) {
		presenter.deleteUser();
		Intent intent = new Intent(this, AdminActivity.class);
		intent.putExtra(MainActivity.USERNAME, adminName);
		startActivity(intent);
	}

	/**
	 * Sends the user back to Main if they click back.
	 * 
	 * @param view
	 */
	public void back(View view) {
		Intent intent = new Intent(this, AdminActivity.class);
		intent.putExtra(MainActivity.USERNAME, adminName);
		startActivity(intent);
	}
}